package com.freight.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.order.dto.EntrustGoodsDto;
import com.freight.order.entity.QuotationDetails;
import com.freight.order.service.CompanyQuotationRecordService;
import com.freight.order.vo.QuotationRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(description = "货主端 --- 报价接口")
@RequestMapping("/freight/companyQuotationRecord")
@Transactional
public class CompanyQuotationRecordController {

    @Autowired
    private CompanyQuotationRecordService companyQuotationRecordService;


    @RequestMapping(value = "/entrustGoods", method = RequestMethod.POST)
    @ApiOperation(value = "货主委托货源")
    public Result<Long> entrustGoods(EntrustGoodsDto entrustGoodsDto) {
        Long entrustId = companyQuotationRecordService.entrustGoods(entrustGoodsDto);
        return new ResultUtil<Long>().setData(entrustId);
    }

    @RequestMapping(value = "/companyQuotationRecord", method = RequestMethod.POST)
    @ApiOperation(value = "根据货源获取报价记录")
    public Result<Page<QuotationRecordVo>> companyQuotationRecord(Long orderGoodsId, String loadTime, PageVo pageVo) {
        Page<QuotationRecordVo> page = companyQuotationRecordService.companyQuotationRecord(orderGoodsId,loadTime, PageUtil.initMpPage(pageVo));
        return new ResultUtil<Page<QuotationRecordVo>>().setData(page);
    }

    @RequestMapping(value = "/quotationModifyList", method = RequestMethod.GET)
    @ApiOperation(value = "获取报价修改记录列表")
    public Result<List<QuotationDetails>> quotationModifyList(Long quotationRecordId) {
        List<QuotationDetails> page = companyQuotationRecordService.quotationModifyList(quotationRecordId);
        return new ResultUtil<List<QuotationDetails>>().setData(page);
    }

}
